package net.xdclass.oss.config;

import lombok.ToString;
import net.xdclass.common.exception.badrequest.MissingPropertyException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.Optional;

/**
 * @author yaya
 */
@ToString
@Configuration
@ConfigurationProperties("oss.tencent")
public class TencentCosProperty {

    String protocol;
    String domain;
    String region;
    String secretId;
    String secretKey;
    String bucketName;
    String source;
    String styleRule;
    String thumbnailStyleRule;

    public String getProtocolOrDefault(){
        return Optional.ofNullable(protocol).orElse("https://");
    }

    public String getDomainOrDefault(){
        return Optional.ofNullable(domain).orElse("");
    }

    public String getRegionOrNonNull(){
        return Optional.ofNullable(region).orElseThrow(() -> new MissingPropertyException("You have to config region setting"));
    }

    public String getSecretIdOrNonNull(){
        return Optional.ofNullable(secretId).orElseThrow(() -> new MissingPropertyException("You have to config secretId setting"));
    }

    public String getBucketNameOrNonNull(){
        return Optional.ofNullable(bucketName).orElseThrow(() -> new MissingPropertyException("You have to config bucketName setting"));
    }

    public String getSourceOrDefault(){
        return Optional.ofNullable(source).orElse("");
    }

    public String getStyleRuleOrNonNull(){
        return Optional.ofNullable(styleRule).orElse("");
    }

    public String getThumbnailStyleRuleOrNonNull(){
        return Optional.ofNullable(thumbnailStyleRule).orElse("");
    }

    public String getSecretKeyOrNonNull(){
        return Optional.ofNullable(secretKey).orElseThrow(() -> new MissingPropertyException("You have to config secretKey setting"));
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public void setRegion(String region) {
        this.region = region;
    }

    public void setSecretId(String secretId) {
        this.secretId = secretId;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public void setStyleRule(String styleRule) {
        this.styleRule = styleRule;
    }

    public void setThumbnailStyleRule(String thumbnailStyleRule) {
        this.thumbnailStyleRule = thumbnailStyleRule;
    }
}
